import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CommonModule } from '@angular/common';
import { CompanyComponent } from './company.component';
import { AuthGuard } from '../../../guards/auth.guard';
import { CompanyService } from './company.service';
import { CompanyHeaderModule } from './shared/companyHeader/companyHeader.module';
import { CompanyMenuModule } from './shared/companyMenu/companyMenu.module';
import { RouteGuard } from '../../../guards/route.guard';
import { Claims, HttpVerb } from '../../../shared/models/claims.model';
import { CompanyResearchWrapperComponent } from './shared/companyResearchWrapper/companyResearchWrapper.component';

const routes: Routes = [
    {
        path: ':id',
        component: CompanyComponent,
        children:[
            {
                path: '',
                redirectTo: 'overview',
                pathMatch: 'full'
            },
            {
                path: 'overview',
                loadChildren: './overview/companyOverview.module#CompanyOverviewModule',
                //data: { preload: true },
                canActivate: [AuthGuard, RouteGuard]
            },
            {
                path: '',
                component: CompanyResearchWrapperComponent,
                children:[
                    {
                        path: 'overview',
                        redirectTo: 'overview',
                        data: {
                            showAsMenu: true,
                            menu: { title: 'Company Overview' }
                        },
                        canActivate: [AuthGuard, RouteGuard]
                    },
                    {
                        path: 'risk',
                        loadChildren: './riskRating/companyRiskRating.module#CompanyRiskRatingModule',
                        data: {
                            showAsMenu: true,
                            menu: { title: 'ESG Risk Rating' },
                            widget: { path: './companyRiskRating.widget#WidgetModule', order: 1 },
                            claim: { resource: 'api/v1/riskratings/{companyId}', verb: HttpVerb.GET },
                            featureField: 'hasRiskRatingAccountFeature'
                        },
                        canActivate: [AuthGuard, RouteGuard]
                    },
                    {
                        path: 'esg',
                        loadChildren: './esg/companyEsg.module#CompanyEsgModule',
                        data: {
                            showAsMenu: true,
                            menu: { title: 'ESG Rating' },
                            widget: { path: './companyEsg.widget#WidgetModule', order: 2 },
                            claim: { resource: 'api/v1/esgratings/{companyId}', verb: HttpVerb.GET },
                            featureField: 'hasEsgAccountFeature'
                        },
                        canActivate: [AuthGuard, RouteGuard]
                    },
                    {
                        path: 'controversies',
                        loadChildren: './controversies/companyControversies.module#CompanyControversiesModule',
                        data: {
                            showAsMenu: true,
                            menu: { title: 'Controversies' },
                            widget: { path: './companyControversies.widget#WidgetModule', order: 4 },
                            claim: { resource: 'api/v1/company/{companyId}/esgControversyIndicator', verb: HttpVerb.GET },
                            featureField: 'hasControversiesAccountFeature'
                        },
                        canActivate: [AuthGuard, RouteGuard]
                    },
                    {
                        path: 'governance',
                        loadChildren: './governance/companyGovernance.module#CompanyGovernanceModule',
                        data: {
                            showAsMenu: true,
                            menu: { title: 'Corporate Governance' },
                            widget: { path: './companyGovernance.widget#WidgetModule', order: 3 },
                            claim: { resource: 'api/v1/governance', verb: HttpVerb.GET },
                            featureField: 'hasGovernanceAccountFeature'
                        },
                        canActivate: [AuthGuard, RouteGuard]
                    },
                    {
                        path: 'sustainableProducts',
                        loadChildren: './sustainableProducts/companySustainableProducts.module#CompanySustainableProductsModule',
                        data: {
                            showAsMenu: true,
                            menu: { title: 'Sustainable Products' },
                            widget: { path: './companySustainableProducts.widget#WidgetModule', order: 7 },
                            claim: { resource: 'api/v1/sp', verb: HttpVerb.GET },
                            featureField: 'hasSPAccountFeature'
                        },
                        canActivate: [AuthGuard, RouteGuard]
                    },
                    {
                        path: 'productInvolvement',
                        loadChildren: './productInvolvement/companyProductInvolvement.module#CompanyProductInvolvementModule',
                        data: {
                            showAsMenu: true,
                            menu: { title: 'Product Involvement' },
                            widget: { path: './companyProductInvolvement.widget#WidgetModule', order: 6 },
                            claim: { resource: 'api/v1/pi', verb: HttpVerb.GET },
                            featureField: 'hasPIAccountFeature'
                        },
                        canActivate: [AuthGuard, RouteGuard]
                    },
                    {
                        path: 'globalcompact',
                        loadChildren: './globalCompact/companyGlobalCompact.module#CompanyGlobalCompactModule',
                        data: {
                            showAsMenu: true,
                            menu: { title: 'Global Compact' },
                            widget: { path: './companyGlobalCompact.widget#WidgetModule', order: 5 },
                            claim: { resource: 'api/v1/gcoverallcompanysummaryextended', verb: HttpVerb.GET },
                            featureField: 'hasGCCSAccountFeature'
                        },
                        canActivate: [AuthGuard, RouteGuard]
                    }
                ]
            }
        ]
    }
];

/**
 * Company module
 *
 * Author: Sorin Spiru
 * Date: 13.01.2018
 */
@NgModule({
    imports: [
        CommonModule,
        CompanyMenuModule,
        CompanyHeaderModule,
        RouterModule.forChild(routes)
    ],
    declarations: [
        CompanyComponent,
        CompanyResearchWrapperComponent
    ]
})
export class CompanyModule { }
